<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
  <meta charset="UTF-8">
  <title>JSAPI功能测试</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
  <meta name="format-detection" content="telephone=no"/>
  <script src="js/data.js"></script>

</head>
<body style="padding-left: 8px;">

<h3>1. 打开手机上其他应用</h3>
<button id="openApp">openApp</button>

<h3>2. 判断设备上面是否已安装指定应用</h3>
<button id="appInstalled">appInstalled</button>

<h3>3. 文件、图片操作</h3>
<button id="fileOperation1">文件是否存在</button>
<button id="fileOperation2">下载pdf</button>
<button id="fileOperation3">下载图片</button>
<button id="fileOperation4">下载视频</button>
<button id="fileOperation5">下载docx</button>
<button id="fileOperation6">下载xlsx</button>

<h3>4.定位</h3>
<button id="getPositioning">getPositioning</button>

<h3>5.设置屏幕旋转</h3>
<button id="setScreenRotation1" style="width: 50px;">up</button>
<button id="setScreenRotation2" style="width: 50px;">down</button>
<button id="setScreenRotation3" style="width: 50px;">left</button>
<button id="setScreenRotation4" style="width: 50px;">right</button>

<h3>6.向系统动态请求权限</h3>
<button id="requestPermission">requestPermission</button>

<h3>7.打开文档（word、ppt、Excel、pdf、文本文档），图片，播放音频，打开压缩包及解压</h3>
<button id="openFileOperation">openFileOperation</button>
<button id="openFileOperation2">Base64图片</button>
<button id="openFileOperation3">Base64文件</button>
<button id="openFileOperation4">Base64文档</button>
<button id="openFileOperation5">Android本地文档</button>
<button id="openFileOperation6">iOS文档</button>

<h3>8.系统截屏操作监听【主动监听】</h3>

<h3>9.支持企业微信分享</h3>
<button id="wx_share1">分享文本</button>
<button id="wx_share2">分享图片</button>
<button id="wx_share3">分享视频</button>
<button id="wx_share4">分享文件</button>
<button id="wx_share5">分享链接</button>

<h3>10.语音识别【主动监听】</h3>
<button id="speech_audio" value="0">audioDictationOperation</button>
<div id="speech_txt" style="background: #99d930;padding: 8px;margin-right:8px;word-break: break-all"></div>

<h3>11.扫描</h3>
<button id="scanningOperation">scanningOperation</button>

<h3>12.写入通讯录</h3>
<button id="addressBookOperation">addressBookOperation</button>

<h3>打开新窗口</h3>
<button id="push_window">pushWindow</button>

<h3>文件上传</h3>
<input type="file" class="muiAttachmentUploadFile" multiple>

<h3>显示base64图片</h3>
<img id="timg" style="width: 100px;height: 100px;"
     src="content://com.jvtd.fileprovider/external/Download/csc/result.png">
</br></br></br>
<script>
  function ready(callback) {
    // 如果 jsbridge 已经注入则直接调用
    if (window.AlipayJSBridge) {
      callback && callback();
    } else {
      // 如果没有注入则监听注入的事件
      document.addEventListener('AlipayJSBridgeReady', callback, false);
    }
  }

  ready(function () {
    const host = window.location.origin + "/mpaas/doc/";
    //1. 打开应用
    document.getElementById('openApp').addEventListener('click', function () {
      AlipayJSBridge.call('openApp', {
        iosUrl: 'wxwork://',
        androidPkg: 'com.tencent.mm' //'com.tencent.mobileqq' //'android.intent.action.VIEW'
        //uri: 'http://www.baidu.com'
        //mineType:''
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });

    //2. 判断手机上是否安装指定应用
    document.getElementById('appInstalled').addEventListener('click', function () {
      AlipayJSBridge.call('appInstalled', {
        appBundle: 'com.tencent.mm' //'com.tencent.mobileqq'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });

    //3. 判断文件存在或者下载 1.只判断文件是否存在 2.只下载文件
    document.getElementById('fileOperation1').addEventListener('click', function () {
      AlipayJSBridge.call('fileOperation', {
        oprationType: 1,
        fileName: 'earth', //'164146.mp4' //'earth.png' //'test.pdf' //'tdoc.docx'
        fileType: 'png', //doc、png,jpg,xls,xlsx,mp3,zip
        fileUrl: host + 'earth.png',
        folderName: 'csc'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });
    document.getElementById('fileOperation2').addEventListener('click', function () {
      AlipayJSBridge.call('fileOperation', {
        oprationType: 2,
        fileName: 'test', //'164146.mp4' //'earth.png' //'test.pdf' //'tdoc.docx'
        fileType: 'pdf', //doc、png,jpg,xls,xlsx,mp3,zip
        fileUrl: host + 'test.pdf',
        folderName: 'csc'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });
    document.getElementById('fileOperation3').addEventListener('click', function () {
      AlipayJSBridge.call('fileOperation', {
        oprationType: 2,
        fileName: 'earth', //'164146.mp4' //'earth.png' //'test.pdf' //'tdoc.docx'
        fileType: 'png', //doc、png,jpg,xls,xlsx,mp3,zip
        fileUrl: host + 'earth.png',
        folderName: 'csc'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });
    document.getElementById('fileOperation4').addEventListener('click', function () {
      AlipayJSBridge.call('fileOperation', {
        oprationType: 2,
        fileName: '164146', //'164146.mp4' //'earth.png' //'test.pdf' //'tdoc.docx'
        fileType: 'mp4', //doc、png,jpg,xls,xlsx,mp3,zip
        fileUrl: host + '164146.mp4',
        folderName: 'csc'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });
    document.getElementById('fileOperation5').addEventListener('click', function () {
      AlipayJSBridge.call('fileOperation', {
        oprationType: 2,
        fileName: 'tdoc', //'164146.mp4' //'earth.png' //'test.pdf' //'tdoc.docx'
        fileType: 'docx', //doc、png,jpg,xls,xlsx,mp3,zip
        fileUrl: host + 'tdoc.docx',
        folderName: 'csc'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });
    document.getElementById('fileOperation6').addEventListener('click', function () {
      AlipayJSBridge.call('fileOperation', {
        oprationType: 2,
        fileName: 'txl', //'164146.mp4' //'earth.png' //'test.pdf' //'tdoc.docx'
        fileType: 'xlsx', //doc、png,jpg,xls,xlsx,mp3,zip
        fileUrl: host + 'txl.xlsx',
        folderName: 'csc'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });

    //4. 定位信息
    document.getElementById('getPositioning').addEventListener('click', function () {
      AlipayJSBridge.call('getPositioning', {}, function (result) {
        alert(JSON.stringify(result))
      });
    });

    //5. 屏幕旋转
    document.getElementById('setScreenRotation1').addEventListener('click', function () {
      AlipayJSBridge.call('setScreenRotation', {
        orientation: 'portrait_up'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });
    document.getElementById('setScreenRotation2').addEventListener('click', function () {
      AlipayJSBridge.call('setScreenRotation', {
        orientation: 'portrait_down'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });
    document.getElementById('setScreenRotation3').addEventListener('click', function () {
      AlipayJSBridge.call('setScreenRotation', {
        orientation: 'landscape_left'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });
    document.getElementById('setScreenRotation4').addEventListener('click', function () {
      AlipayJSBridge.call('setScreenRotation', {
        orientation: 'landscape_right'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });

    //6. 动态请求权限
    document.getElementById('requestPermission').addEventListener('click', function () {
      AlipayJSBridge.call('requestPermission', {
        list: ['camera', 'storage', 'microphone', 'contacts', 'location']
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });

    //7.打开文档
    document.getElementById('openFileOperation').addEventListener('click', function () {
      AlipayJSBridge.call('openFileOperation', {
        fileName: 'tdoc', //'164146.mp4' //'earth.png' //'test.pdf' //'tdoc.docx'
        fileType: 'docx', //doc、png,jpg,xls,xlsx,mp3,zip
        fileUrl: host + 'tdoc.docx',
        folderName: 'csc'
      }, function (result) {
        alert(JSON.stringify(result));
      });
    });
    document.getElementById('openFileOperation2').addEventListener('click', function () {
      AlipayJSBridge.call('openFileOperation', {
        fileName: 'bitmap', //'earth.png' //'test.pdf' //'tdoc.docx'
        fileType: 'jpg', //doc、png,jpg,xls,xlsx,mp3,zip
        fileUrl: bitmap,
        folderName: 'csc'
      }, function (result) {
        alert(JSON.stringify(result));
      });
    });
    document.getElementById('openFileOperation3').addEventListener('click', function () {
      AlipayJSBridge.call('openFileOperation', {
        fileName: 'test_pdf', //'earth.png' //'test.pdf' //'tdoc.docx'
        fileType: 'pdf', //doc、png,jpg,xls,xlsx,mp3,zip
        fileUrl: pdf,
        folderName: 'csc'
      }, function (result) {
        alert(JSON.stringify(result));
      });
    });
    document.getElementById('openFileOperation4').addEventListener('click', function () {
      AlipayJSBridge.call('openFileOperation', {
        fileName: 'test_docx', //'earth.png' //'test.pdf' //'tdoc.docx'
        fileType: 'docx', //doc、png,jpg,xls,xlsx,mp3,zip
        fileUrl: 'tdoc.docx', //
        folderName: 'csc'
      }, function (result) {
        alert(JSON.stringify(result));
      });
    });
    document.getElementById('openFileOperation5').addEventListener('click', function () {
      AlipayJSBridge.call('openFileOperation', {
        fileUrl: 'content://com.jvtd.fileprovider/external/Download/csc/result.png',
      }, function (result) {
        alert(JSON.stringify(result));
      });
    });
    document.getElementById('openFileOperation6').addEventListener('click', function () {
      AlipayJSBridge.call('openFileOperation', {
        fileUrl: '/var/mobile/Containers/Data/Application/CB051799-96CF-45BD-9721-C361912A3FBE/Documents/zxjtFile/csc/tdoc.docx',
      }, function (result) {
        alert(JSON.stringify(result));
      });
    });

    //8. 截屏通知
    document.addEventListener('screenCaptureOperation', function (e) {
      alert("截屏，" + JSON.stringify(e));
    }, false);

    //9. 企业微信分享
    document.getElementById('wx_share1').addEventListener('click', function () {
      AlipayJSBridge.call('wxShare', {
        type: 'text',
        content: '分享内容'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });
    document.getElementById('wx_share2').addEventListener('click', function () {
      AlipayJSBridge.call('wxShare', {
        type: 'image',
        fileName: 'earth.png',
        filePath: '/storage/emulated/0/Download/csc/earth.png'
        // filePath: '/var/mobile/Containers/Data/Application/1446372B-E04D-436C-8D03-0C2FF88DAA68/Documents/zxjtFile/csc/earth.png'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });
    document.getElementById('wx_share3').addEventListener('click', function () {
      AlipayJSBridge.call('wxShare', {
        type: 'video',
        fileName: '164146.mp4',
        // filePath: '/storage/emulated/0/Download/csc/164146.mp4'
        filePath: '/var/mobile/Containers/Data/Application/1446372B-E04D-436C-8D03-0C2FF88DAA68/Documents/zxjtFile/csc/164146.mp4'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });
    document.getElementById('wx_share4').addEventListener('click', function () {
      AlipayJSBridge.call('wxShare', {
        type: 'file',
        fileName: 'tdoc.docx',
        // filePath: '/storage/emulated/0/Download/csc/tdoc.docx'
        filePath: '/var/mobile/Containers/Data/Application/1446372B-E04D-436C-8D03-0C2FF88DAA68/Documents/zxjtFile/csc/tdoc.docx'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });
    document.getElementById('wx_share5').addEventListener('click', function () {
      AlipayJSBridge.call('wxShare', {
        type: 'link',
        title: '测试分享链接',
        description: '这里是分享链接的内容',
        thumbUrl: 'https://himg.bdimg.com/sys/portrait/item/public.1.b2bdc34.GiCJRAL3pffpU9FYu90cGQ.jpg',
        webpageUrl: 'http://www.baidu.com'
      }, function (result) {
        alert(JSON.stringify(result))
      });
    });

    //10. 语音识别
    document.getElementById('speech_audio').addEventListener('click', function () {
      var status = document.getElementById('speech_audio').valueOf().value;
      AlipayJSBridge.call('audioDictationOperation', {
        type: status
      }, function (result) {
        alert(JSON.stringify(result));
      });
      if (status == '0') {
        document.getElementById('speech_audio').valueOf().value = '1';
      } else {
        document.getElementById('speech_audio').valueOf().value = '0';
      }
    });
    document.addEventListener('audioDictationOperation', function (e) {
      document.getElementById('speech_txt').innerHTML = JSON.stringify(e);
    }, false);

    //11. 扫码
    document.getElementById('scanningOperation').addEventListener('click', function () {
      AlipayJSBridge.call('scanningOperation', {}, function (result) {
        alert(JSON.stringify(result));
      });
    });

    //12. 写通讯录
    document.getElementById('addressBookOperation').addEventListener('click', function () {
      AlipayJSBridge.call('addressBookOperation', {
        name: '赵泓博',
        mobile: '17600106002',
        email: 'zhaozf@jvtd.com',
        company: '聚通达集团',
        address: '北京市朝阳区四惠东艺术博览园C座4楼',
        position: '搬砖工',
        phone: '010-11221126'
      }, function (result) {
        alert(JSON.stringify(result));
      });
    });

    // 打开淘宝首页，自动读取 title，并且去除右边菜单
    document.getElementById('push_window').addEventListener('click', function () {
      AlipayJSBridge.call('pushWindow', {
        // url: 'https://qyhtest.csc.com.cn/index.php?s=/addon/Zjwtest/mobile/index',
        url: 'https://qyhtest.csc.com.cn/index.php?s=/addon/Zjwtest/mobile/index',
        param: {
          readTitle: true,
          showOptionMenu: false,
          showTitleBar: false
          // gestureBack: 0
        }
      });
    });
  });
  //加载base64
  document.getElementById('timg').src = "data:image/png;base64," + bitmap;
</script>
</body>
</html>
